package com.gege.homework2;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author gechenpeng
 * @date 2021-04-16
 */
//@Component
public class School implements ISchool, BeanNameAware, ApplicationContextAware, InitializingBean, DisposableBean {

    private String beanName;

    private ApplicationContext applicationContext;

    @Autowired
    private Klass klass;

    private void init1() {
        System.out.println("init-method");
    }

    @PostConstruct
    public void init() {
        System.out.println("PostConstruct");
    }

    @Override
    public void doSomething() {
        System.out.println("beanName: " + beanName);
        System.out.println("school has " + klass.getStudents().size() + " students");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("setBeanName...");
        this.beanName = s;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext...");
        this.applicationContext = applicationContext;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("destroy...");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet...");
    }
}
